package com.lagou.homework1_4;

public class Employee {

    private String name;
    private int age;

    public Employee() {
    }

    public Employee(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }


    public void setName(String name) {
        //如果姓名为null或者""抛出空异常
        if(null == name || "".equals(name)){
            throw new NullPointerException();
        }else {
            this.name = name;
        }
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if (age >= 18 && age <= 150) {
            this.age = age;
        } else {
            // 如果年龄小于18龄大于150抛出年龄异常
            try {
                throw new AgeException("年龄不合理！");
            } catch (AgeException e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
